<template>
    <div class=''>
        <div ref="ViewPaperworkidref" class="llkkmmsweewe">
            <div class="pr sdfsdrtrgtr">
                <div id="divId" style="text-align: center"></div>
            </div>
        </div>
    </div>
</template>
<script lang='ts' setup>
import { ref } from "vue"
import { parseOfdDocument, renderOfd } from "ofd.js";
const ViewPaperworkidref = ref()
// let props = defineProps({
//     ofd: { type: String }
// })

const emit = defineEmits(["zhsuccess"]);
defineExpose({
    odfzpdf(ofd) {
        parseOfdDocument({
            // ofd写入文件地址
            ofd: ofd,
            success(res) {
                //输出ofd每页的div
                let screenWidth = 800;
                const divs = renderOfd(screenWidth, res[0]);
                let contentDiv = document.getElementById('divId');
                contentDiv.innerHTML = '';
                let kkjse = ''
                const obj = {
                    name: "",
                    dutyParagraph: "",
                    invoiceNumber: "",//发票号码
                    invoiceDate: "",//开票日期
                    SellerCompany: "",//销售方信息
                    SellerTaxNumber: "",//销售方纳税号
                    ProjectList: [{
                        name: "",
                        money: "",//金额
                        taxRate: "",//税率
                        Tax: "", //税额
                    }],//项目列表
                    amountTotal: "",//合计金额
                    AggregateTax: "", // 合计税额
                    TotalTaxTnWords: "",//合计税额大写
                    drawer: ""//开票人
                }
                for (const div of divs) {
                    contentDiv.appendChild(div);
                    const kjnmeer = div.childNodes
                    for (let i = 0; i < kjnmeer.length; i++) {
                        const leftNumber = kjnmeer[i].style.left.replaceAll('px', '')
                        const TopNumber = kjnmeer[i].style.top.replaceAll('px', '')

                        // 获取发票号码
                        if ((leftNumber >= 640 && leftNumber <= 650) && (TopNumber >= 34 && TopNumber <= 45)) {
                            obj.invoiceNumber = kjnmeer[i].textContent
                        }
                        // 开票日期
                        if ((leftNumber >= 640 && leftNumber <= 650) && (TopNumber >= 57 && TopNumber <= 67)) {
                            obj.invoiceDate = kjnmeer[i].textContent
                        }
                        // 公司名称 购
                        if ((leftNumber >= 71 && leftNumber <= 81) && (TopNumber >= 123 && TopNumber <= 133)) {
                            obj.name = kjnmeer[i].textContent
                        }
                        // 税号 购
                        if ((leftNumber >= 200 && leftNumber <= 210) && (TopNumber >= 159 && TopNumber <= 169)) {
                            obj.dutyParagraph = kjnmeer[i].textContent
                        }
                        // 销售方信息
                        if ((leftNumber >= 451 && leftNumber <= 461) && (TopNumber >= 123 && TopNumber <= 133)) {
                            obj.SellerCompany = kjnmeer[i].textContent
                        }
                        // 销售方纳税号
                        if ((leftNumber >= 582 && leftNumber <= 592) && (TopNumber >= 159 && TopNumber <= 169)) {
                            obj.SellerTaxNumber = kjnmeer[i].textContent
                        }
                        // 项目名称
                        if ((leftNumber >= 12 && leftNumber <= 22) && (TopNumber >= 207 && TopNumber <= 217)) {
                            obj.ProjectList[0].name = kjnmeer[i].textContent
                        }
                        // 金额
                        if ((leftNumber >= 479 && leftNumber <= 489) && (TopNumber >= 208 && TopNumber <= 218)) {
                            obj.ProjectList[0].money = kjnmeer[i].textContent
                        }
                        // 税率
                        if ((leftNumber >= 580 && leftNumber <= 590) && (TopNumber >= 208 && TopNumber <= 218)) {
                            obj.ProjectList[0].taxRate = kjnmeer[i].textContent
                        }
                        // 税额
                        if ((leftNumber >= 675 && leftNumber <= 685) && (TopNumber >= 208 && TopNumber <= 218)) {
                            obj.ProjectList[0].Tax = kjnmeer[i].textContent
                        }

                        // 合计金额
                        if ((leftNumber >= 479 && leftNumber <= 489) && (TopNumber >= 338 && TopNumber <= 348) && kjnmeer[i].textContent != '¥') {
                            obj.amountTotal = kjnmeer[i].textContent
                        }
                        // 合计税额
                        if ((leftNumber >= 677 && leftNumber <= 687) && (TopNumber >= 338 && TopNumber <= 348) && kjnmeer[i].textContent != '¥') {
                            obj.AggregateTax = kjnmeer[i].textContent
                        }
                        // 合计税额大写
                        if ((leftNumber >= 234 && leftNumber <= 244) && (TopNumber >= 359 && TopNumber <= 369)) {
                            obj.TotalTaxTnWords = kjnmeer[i].textContent
                        }
                        // 开票人
                        if ((leftNumber >= 116 && leftNumber <= 126) && (TopNumber >= 485 && TopNumber <= 495)) {
                            obj.drawer = kjnmeer[i].textContent
                        }
                    }
                }
                emit("zhsuccess", obj)
            },
            fail(error) {
                console.log(error)
            }
        });
    }
})



</script>
<style scoped>
/* .llkkmmsweewe {
    position: fixed;
    left: -2px;
    top: -2px;
    width: 1px;
    height: 1px;
    z-index: 1;
    background: #fff;
    opacity: 0;
    overflow: hidden;
} */
</style>